import { Tween } from "cc"
import { Vec3 } from "cc"
import { _decorator, Component, Node } from "cc"
const { ccclass, property } = _decorator

@ccclass("GuideHand")
export class GuideHand extends Component {
  start() {
    // this.firstScale = this.node.scaleX
    // this.schedule(this.updateZIndex, 0.1)
  }

  updateZIndex() {
    // this.node.setSiblingIndex(this.node.parent.children.length - 1)
  }

  update(deltaTime: number) {}
  protected onDisable(): void {
    Tween.stopAllByTarget(this.node)
  }

  initGuideMovePos(startPos: Vec3, endPos: Vec3) {
    let time = 0.6 //util.getTwoPosXYLength(startPos.x, startPos.y, endPos.x, endPos.y) / 200
    new Tween(this.node)
      .call(() => {
        this.node.setPosition(startPos)
      })
      .to(0.1, { alpha: 1 })
      .to(time, { position: endPos })
      .to(0.1, { alpha: 0 })
      .union()
      .repeatForever()
      .start()
  }

  private firstScale: number = 0
  initGuideTouch(touchPos: Vec3) {
    this.firstScale = 0.9
    this.node.scaleXYZ = this.firstScale
    this.node.alpha = 0
    new Tween(this.node).to(0.5, { alpha: 1 }).start()
    this.node.setPosition(touchPos)
    new Tween(this.node)
      .to(0.5, { scaleXYZ: 0.8 * this.firstScale })
      .to(0.5, { scaleXYZ: this.firstScale })
      .delay(0.2)
      .union()
      .repeatForever()
      .start()
  }
}
